/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package netfone;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author bruno
 */
class UserService {

    private static UserService instance = null;
    private UserDao dao = new UserDaoDB4o();

    public List<User> getUsers() {
        return dao.getUsers();
    }

    public boolean saveUser(User user) {
        return dao.saveUser(user);

    }

    public boolean removeUser(User user) {
        return dao.removeUser(user);
    }

    public static UserService getService() {
        if (instance == null) {
            instance = new UserService();
        }
        return instance;
    }

    public void loadUser(User user) {
        dao.loadUser(user);
    }
    
    public List<Contact> getAllContacts(){
        return dao.getAllContacts();
    }

    public Map<User, Double> getTotalByUser(List<Call> calls) {
        Map<User, Double> resultMap = new HashMap<User, Double>();
        List<User> users = getUsers();
        for (Call call : calls) {
            for(User user: users){
                if(!resultMap.containsKey(user)){
                    resultMap.put(user,new Double(0));
                }
                if (user.getContacts().contains(new Contact(call.getDialedNumber()))){
                    Double parcialValue = resultMap.get(user);
                }
            }
        }

        return resultMap;
    }
}
